<template>
  <div
    :id="pageData.nodeId"
    class="MaterialNode_container"
    @mouseenter="mouseenterEdit"
    @mouseleave="mouseleaveEdit"
  >

    <div class="MaterialNode_main">

      <!-- <div v-if="graphData&&graphData.edges.length>0&&graphData.edges.some(item=>item.target==pageData.nodeId)" class="MaterialNode_main_header">1:{{ pageData.demandNumber }}</div> -->
      <div class="MaterialNode_main_middle">
        <!--        <div class="MaterialNode_main_middle1">{{ itemData.data.materialName }}：{{ pageData.nodeId }}</div>-->
        <div class="MaterialNode_main_middle1">{{ itemData.data.materialName }}</div>
        <div v-if="graphData" class="MaterialNode_main_number">{{ pageData.demandNumber }}</div>
        <!-- <div v-if="itemData.data.materialModel" class="MaterialNode_main_middle2">{{ itemData.data.materialModel }}</div> -->
      </div>
      <div class="MaterialNode_main_code">
        {{ itemData.data.materialCode }}
      </div>
      <!--      <div class="MaterialNode_main_bottom">-->
      <!--        <div class="MaterialNode_main_bottom_item">{{ pageData.productBySelf&&pageData.productBySelf=='1'?'自己生产':'外协' }}</div>-->
      <!--        <div class="MaterialNode_main_bottom_item">{{ pageData.productBySelf&&pageData.toInspect=='1'?'送检':'不送检' }}</div>-->
      <!--        <div class="MaterialNode_main_bottom_item">{{ pageData.productBySelf&&pageData.toWms=='1'?'入库':'不入库' }}</div>-->
      <!--      </div>-->
    </div>
    <div v-if="$store.state.engineeringManage.showDetail" class="MaterialNode_right">

      <el-popover
        placement="right"
        width="330"
        trigger="click"
        :visible-arrow="false"
        popper-class="MaterialNode_popover"
        @show="popoverShow"
        @hide="popoverHide"
      >
        <div class="MaterialNode_hover">

          <div v-if="graphData" class="MaterialNode_hover_item">
            <div class="MaterialNode_hover_item_name">
              <label class="bitian">*</label>领退料限制
            </div>
            <div class="MaterialNode_hover_item_value">
              <el-radio-group v-model="pageData.requisitionOrReturn" @change="updateNodeDatas">
                <el-radio label="1">是</el-radio>
                <el-radio label="0">否</el-radio>
              </el-radio-group>
            </div>
          </div>
          <div v-if="graphData" class="MaterialNode_hover_item">
            <div class="MaterialNode_hover_item_name">
              <label class="bitian">*</label>需求数量
            </div>
            <div class="MaterialNode_hover_item_value">
              <el-input
                v-model="pageData.demandNumber"
                type="number"
                placeholder="请输入"
                @input="updateNodeDatas"
              />
            </div>
          </div>
        </div>
        <div v-show="showEdit" slot="reference" class="MaterialNode_main_edit animate__animated animate__fadeInLeft">
          <!--          <svg-icon icon-class="edit" />-->
          编辑
        </div>

      </el-popover>

      <div v-if="showEdit" slot="reference" class="MaterialNode_main_edit MaterialNode_main_delete animate__animated animate__fadeInLeft" @click="deleteNode">
        删除
      </div>
    </div>
  </div>
</template>

<script>
import 'animate.css'
import { mapGetters } from 'vuex'
import { ButterflyVueEndpoint } from 'butterfly-vue'
export default {
  name: 'MaterialNode',
  components: {
    ButterflyVueEndpoint
  },
  computed: {
    ...mapGetters([
      'graphData', 'processNodeData', 'isAllowEdit', 'isEnable'
    ]),
    isShow() {
      if ((this.isAllowEdit && this.isEnable) || (!this.isEnable)) {
        return true
      } else {
        return false
      }
    }
  },
  props: {
    // 这里可以拿到mockdata里的当前节点的数据
    itemData: {
      type: Object
    }
  },
  data() {
    return {
      showEdit: false,
      showEdit2: false,
      showProcessPopover: undefined,
      showPopover: false,
      pageData: {
        id: '',
        code: '',
        nodeId: '',
        materialId: '',
        versionCode: '',
        isEqual: '0',
        requisitionOrReturn: '1',
        demandNumber: '1',
        productBySelf: '1',
        toInspect: '1',
        toWms: '1'
      }
    }
  },
  watch: {
    graphData() {
    }
  },
  created() {
    Object.keys(this.pageData).forEach(key => {
      this.pageData[key] = this.itemData.data[key] ? JSON.parse(JSON.stringify(this.itemData.data[key])) : ''
    })
    console.log('this.pageData', this.pageData)
  },
  mounted() {
  },
  methods: {
    mouseenterEdit() {
      this.showEdit = true
      this.showEdit2 = true
    },
    mouseleaveEdit() {
      if (!this.showPopover) {
        this.showEdit2 = false
        setTimeout(() => {
          if (!this.showEdit2) {
            this.showEdit = false
          }
        }, 200)
      }
    },
    popoverShow() {
      this.showPopover = true
      this.showProcessPopover = true
    },
    popoverHide() {
      this.showPopover = false
      this.showEdit = false
    },
    chooseProcess(item) {
      this.showPopover = false
      this.showEdit = false
      this.showProcessPopover = false
      // this.$parent.addProcessCallback(item)
      this.$store.state.engineeringManage.addProcessData = {
        fromData: this.itemData,
        toData: item
      }
    },
    updateNodeDatas() {
      console.log(1111, this.pageData)
      this.$store.commit('engineeringManage/CHANGE_SETTING', this.$deepClone(this.pageData))
      // this.$store.state.engineeringManage.updateNodeData = this.$deepClone(this.pageData)
    },
    deleteNode() {
      this.$store.commit('engineeringManage/CHANGE_DELETE', this.$deepClone(this.pageData))
    }
  }
}
</script>

<style lang="less" scoped>

/deep/ .el-radio__label{
  color: #333333;
}
.MaterialNode_container{
  width: 174px;
  //height: 70px;
  display: flex;align-items: center;
  //position: relative;
}
.MaterialNode_main {
  // line-height: 1;
  z-index: 1000;
  width: 174px;
  //height: 70px;
  display: flex;
  flex-direction: column;
  border-radius: 5px;
  color: #333333;
  background-color: #fff;
  //background-color: rgba(142, 176, 240,1);
  // border: 2px solid rgb(56, 123, 252);

  .MaterialNode_main_header{
    font-size: 12px;margin-top: 4px;margin-left: 4px;
    color: #666666;
  }
  .MaterialNode_main_middle{
    height: 24px;
    line-height: 24px;
    background-color: #4FAEFF;
    padding-left: 11px;
    // color: white;
    border-radius: 4px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    // margin-left: 4px;
  }
  .MaterialNode_main_number{
    background-color: #F0F5FC;
    border-radius:2px ;
    margin-right: 4px;
    padding:0 3px;
    height: 16px;
    line-height: 16px;
    font-size: 12px;
    color: #666666;

  }
  .MaterialNode_main_middle1{
    // font-weight: bold;line-height: 1;
    overflow:hidden; //超出的文本隐藏
    text-overflow:ellipsis; //溢出用省略号显示
    white-space:nowrap; //溢出不换行
    color: white;
  }
  .MaterialNode_main_middle2{
    font-weight: bold;line-height: 1;
    font-size: 12px;color: #666666;
    overflow:hidden; //超出的文本隐藏
    text-overflow:ellipsis; //溢出用省略号显示
    white-space:nowrap; //溢出不换行
  }
  .MaterialNode_main_code{
    padding: 4px 0 4px 10px;
    font-size: 12px;
  }
  .MaterialNode_main_bottom{
    display: flex;align-items: center;
    margin-bottom: 4px;
    margin-top: 1px;
    .MaterialNode_main_bottom_item{
      margin-left: 8px;
      // border: 2px solid orange;
      font-size: 12px;
      color: #999999;
      display: flex;align-items: center;
      margin-bottom: 4px;
    }
  }
}
.MaterialNode_right{
  position: absolute;
  left: 180px;
}
.MaterialNode_main_edit{
  cursor: pointer;
  width: 60px;height: 25px;border-radius: 5px;
  margin-left: 10px;color: white;
  background-color: #4FAEFF;font-size: 12px;
  display: flex;align-items: center;justify-content: center;
  padding: 2px 4px;
}
.MaterialNode_main_choose{
  background-color: #1DC68E;
  margin-top: 5px;
}
.MaterialNode_main_delete{
  background-color: #FF6370;
  margin-top: 5px;
}
</style>
<style lang="less" >
.MaterialNode_popover{
  background-color: #fff;
  border-left: 2px solid rgb(56, 123, 252);
  .MaterialNode_hover_item{
    display: flex;align-items: center;
    height: 35px;
    // border-bottom: 1px solid rgb(56, 123, 252);
    .MaterialNode_hover_item_name{
      width: 120px;
      color: #333333;
      font-size: 14px;
    }
    .MaterialNode_hover_item_value{
      flex: 1;
      .el-input__inner{
        height: 25px;
        line-height: 1;
      }
    }
  }
  .MaterialNode_hover_item:last-child{
    border: 0;
  }
  .MaterialNode_hover{

    .MaterialNode_hover_header{
      display: flex;align-items: center;justify-content: center;
      height: 30px;font-weight: bold;
      background-color: #1DC68E;color: white;
      border-top-left-radius:4px ;
      border-top-right-radius:4px ;
    }
    .MaterialNode_hover_list{
      overflow-y: auto;
      max-height: 400px;
      .MaterialNode_hover_list_item{
        cursor: pointer;
        display: flex;align-items: center;
        height: 30px;
        // border-bottom: 1px solid #eef0f4;
        font-size: 14px;
        color: #666666;
        padding: 0 20px;
      }
      // .MaterialNode_hover_list_item:last-child{
      //   border-bottom:0;
      // }
      .MaterialNode_hover_list_item:hover{
        color: white;
        background-color: rgba(142, 176, 240,1);
      }
    }
  }
}
.MaterialNode_popover_process{
  padding: 0;
  border: none !important;
}
</style>
